﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TasksModel
{
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "http://mp.tasks.com/2010/", IsNullable = false)]
    public class GoogleCalendarSynchSettings : SynchSettings
    {
        #region Properties

        private string _login;

        /// <summary>
        /// Required. Email form.
        /// </summary>
        public string Login
        {
            [System.Diagnostics.DebuggerStepThrough]
            get { return _login; }
            set
            {
                if (!object.ReferenceEquals(_login, value))
                {
                    _login = value;
                    NotifyPropertyChanged("Login");
                }
            }
        }

        private string _password;

        /// <summary>
        /// Required.
        /// </summary>
        //TODO secure on xml serialization by symetric encrypt with ID
        public string Password
        {
            [System.Diagnostics.DebuggerStepThrough]
            get { return _password; }
            set
            {
                if (!object.ReferenceEquals(_password, value))
                {
                    _password = value;
                    NotifyPropertyChanged("Password");
                }
            }
        }

        private string _calendar;

        /// <summary>
        /// Required. URL of calendar.
        /// </summary>
        /// <remarks>Example: http://www.google.com/calendar/feeds/your%40gmail.com/private/full</remarks>
        public string Calendar
        {
            [System.Diagnostics.DebuggerStepThrough]
            get { return _calendar; }
            set
            {
                if (!object.ReferenceEquals(_calendar, value))
                {
                    _calendar = value;
                    NotifyPropertyChanged("Calendar");
                }
            }
        }

        #endregion

        #region ISynchSettings Members

        public override bool IsConfigured
        {
            get
            {
                return
                    !string.IsNullOrEmpty(Login) &&
                    !string.IsNullOrEmpty(Password) &&
                    !string.IsNullOrEmpty(Calendar);
            }
        }

        public override string ProviderName { get { return "Google Calendar"; } }

        #endregion

        #region Constructors

        public GoogleCalendarSynchSettings(Guid id)
        {
            ID = id;
        }

        public GoogleCalendarSynchSettings()
            : this(Guid.NewGuid())
        {
        }

        /// <summary>
        /// Deep copy. Does not copy events.
        /// </summary>
        public GoogleCalendarSynchSettings(GoogleCalendarSynchSettings ss)
            : this(ss.ID)
        {
            Login = ss.Login;
            Password = ss.Password;
            Calendar = ss.Calendar;
            Mode = ss.Mode;
            Timestamp = ss.Timestamp;
        }

        #endregion
    }
}